package twelfth.回退流;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;

public class 操作回退流 {
    public static void main(String[] args) throws IOException {
   /*     String s ="www.baidu.com";
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
        PushbackInputStream pbis = new PushbackInputStream(bais);
        System.out.println("读取之后的数据为：");
        int temp = 0;
        while((temp=pbis.read())!=-1){
            if(temp=='.'){
                pbis.unread(temp);//回退到缓冲区前面
                temp=pbis.read();//空出此数据
                System.out.print("(退回"+(char)temp+")");
            }else{
                System.out.print((char)temp);
            }
        }*/
        String s ="https://localhost://file";
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
        PushbackInputStream pbis = new PushbackInputStream(bais);
        int temp = 0;
        System.out.print("读取之后的数据是：");
        while ((temp=pbis.read())!=-1){
            if(temp=='/'){
                pbis.unread(temp);
                temp=pbis.read();//空出此数据
                System.out.print("退回("+(char)temp+")");
            }else{
                System.out.print((char)temp);
            }
        }
    }
}
